********************************************************************************************
**************************** Código para la generación *************************************
********* de tablas de balance  (EscuelasParticipantes vs. No Participantes) ***************

clear
set more off
use "$base_out/911_All_Collapsed.dta"

eststo clear
	label var T_profe "Number of teachers "
	label var T_estu "Number of students "
	label var f_studteach_ratio "Student-teacher ratio"
	label var mathIV "Students in math achievement L-IV (\%)" 			
	label var mathI "Students in math achievement L-I (\%)" 		 			
	label var langI "Students in language achievement L-I (\%)" 		
	label var langIV "Students in language achievement L-IV (\%)"  
	label var Marginalization_ "Marginalization"
	label var Urbanas "Urbanization"
	

	

*****************************************************
******* Participant Schools vs. NonParticipants *****
*****************************************************


	***************** All schools in the country *******************
	eststo PyNP:  my_ptest_treat_vs_notreat mathIV mathI langIV langI Marginalization_ Urbanas T_estu T_profe f_studteach_ratio , by(Participante) clus_id(clavecct) 
	 

	 	 esttab PyNP  using "$tables/Balance_PyNP_allSchools.tex", label replace  nolines nogaps fragment ///
	 star(* 0.1 ** 0.05 *** 0.01)  ///
	 mlabels(none) nomtitles nonumbers noobs nodep collabels(none)  ///
     cells("mu_t(fmt(%9.2fc)) mu_nt(fmt(%9.2fc)) dift(fmt(%9.2fc) star pvalue(d_pt))" "se_t(par) se_nt(par) des_t(par)") 
	
	 foreach var in mathIV mathI langIV langI Marginalization_ Urbanas T_estu T_profe f_studteach_ratio{
		reg `var'  TD1 TD2, nocons vce(cluster clavecct) 
		sum `var' if TD1==1 & e(sample)==1
		local tempm=string(r(N), "%9.2gc")
		file open newfile using "$tables/N_`var'_NoParticipa.tex", write replace
		file write newfile "`tempm'"
		file close newfile
		sum `var' if TD2==1 & e(sample)==1
		local tempm=string(r(N), "%9.2gc")
		file open newfile using "$tables/N_`var'_Participa.tex", write replace
		file write newfile "`tempm'"
		file close newfile
	
		sum `var' if (TD1==1 | TD2==1) & e(sample)==1
		local tempm=string(r(N), "%9.2gc")
		file open newfile using "$tables/N_`var'_Dif_NPvsP.tex", write replace
		file write newfile "`tempm'"
		file close newfile
		}


	 	

